﻿// lc.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <iostream>
#include "algorithm/LinkedListAlgo.h"
#include "algorithm/ArrayStack.h"
#include "1_two_num.hpp"
#include "3_remove_duplicate_from_sorted_array.hpp"
#include "33_search_in_rotated_sorted_array.hpp"
#include "344_reverse_string.hpp"
#include "231_is_power_of_two.hpp"
#include "557_reverse_words.hpp"
#include "9_is_palindrome.hpp"
#include "reflection/MyClass.h"
#include "100_199.hpp"
#include "200_299.hpp"
#include "algorithm/sort.hpp"
#include "00_99.hpp"
#include "1200_1299.hpp"
#include "300_1199.hpp"
#include "thread/thd2.hpp"
#include "thread/thd41.hpp"
#include "thread/thd421.hpp"

void func_1()
{
	// 1.two num
	std::vector<int> nums = { 3,3 };
	int target = 6;
	Solution1 s;
	std::vector<int> results = s.twoSum2(nums, target);
}

void func_2()
{

}

void func_3()
{
	std::vector<int> nums = {1,1,1,2,2,2,3,3,4};
	Solution3 s;
	int res = s.removeDuplicates(nums);
}

void func_33()
{
	std::vector<int> nums = { 4,5,6,7,0,1,2,3 };
	int target = 2;
	Solution33 s;
	int res = s.search(nums, target);
}

void func_81()
{
	std::vector<int> nums = { 4,5,6,6,7,0,1,2,3,4,4 };
	int target = 2;
	Solution81 s;
	bool res = s.search(nums, target);
}

void func_334()
{
	std::vector<char> nums = { 'a','b','c','d','e','f'};
	Solution344 s;
	s.reverseString(nums);
}

void func_231()
{
	Solution231 s;
	bool b = s.isPowerOfTwo(16);
}

void func_557()
{
	Solution557 s;
	std::string ss = "Let's take LeetCode contest";
	std::string s2 = s.reverseWords(ss);
}

void func_9()
{
	int x = 1234321;
	Solution9 s;
	bool b = s.isPalindrome(x);
	bool b1 = s.isPalindrome(12322);
}

void func_136()
{
	Solution136 s;
	std::vector<int> v = { 4, 1, 2, 1, 2 };
	int r = s.singleNumber(v);
}

void func_lambda(const std::string & str)
{
	auto func2 = [str]()
	{
		std::cout << str.c_str() << std::endl;
	};
}

void func_testoctree()
{
	std::uint8_t octant = 1;
	std::uint32_t child_octants = ~0;
	std::uint32_t index = 0;

	// index from octant
	{
		index = (child_octants >> (octant * 4)) & 0xf;
	}
}

void func_test_reflect()
{
	// 注册MyClass类和成员
	Reflect<MyClass>* r = &Reflect<MyClass>::GetInstance();
	std::string strx("x"), stry("y"), strprint("Print"), straddz("AddZ");
	r->Regist(&MyClass::x, std::string("x"))
		->Regist(&MyClass::y, stry)
		->Regist(&MyClass::Print, strprint)
		->Regist(&MyClass::AddZ, straddz);

	MyClass c;
	r->SetObjectAttribute(c, "x", 3.0f);
	r->SetObjectAttribute(c, "y", 999);
	r->CallObjectFunction(c, "AddZ", 4);
	r->CallObjectFunction(c, "Print");
}

void func_237()
{
	Solution237::ListNode* head = new Solution237::ListNode(4); 
	Solution237::ListNode* node5 = new Solution237::ListNode(5);  head->next = node5;
	Solution237::ListNode* node1 = new Solution237::ListNode(1);  node5->next = node1;
	Solution237::ListNode* node9 = new Solution237::ListNode(9);  node1->next = node9; node9->next = nullptr;

	Solution237 s;
	s.deleteNode(node5);
}

void func_test_sort()
{
	int a[6] = {3,5,4,1,2,6};
	bubble_sort(a, 6);
}

void func_test_sort2()
{
	int a[6] = {4,5,6,1,2,3};
	//insertion_sort(a, 6);
	workbook1::insertion_sort(a, 6);
}

void func_test_sort3()
{
	int a[6] = { 4,5,6,1,2,3 };
	//selection_sort(a, 6);
	workbook1::selection_sort(a, 6);
}

void func_test_sort4()
{
	int a[6] = { 4,5,6,1,2,3 };
	//merge_sort(a, 6);
	workbook1::merge_sort(a, 6);
}

void func_test_sort5()
{
	int a[6] = { 4,5,6,1,2,3 };
	quick_sort(a, 6);
}

void func_test_kth()
{
// 	int a[6] = { 4,5,6,1,2,3 };
// 	int value;
// 	find_kth(a, 6, 3, &value);

	std::vector<int> a = { 1};

	Solution215 s;
	int value = s.findKthLargest(a, 1);
}

void func_236()
{
	using TreeNode = Solution236::TreeNode;
	TreeNode* n1 = new TreeNode(1);
	TreeNode* n2 = new TreeNode(2);
	TreeNode* n3 = new TreeNode(3);
	TreeNode* n4 = new TreeNode(4);
	TreeNode* n5 = new TreeNode(5);
	TreeNode* n6 = new TreeNode(6);
	TreeNode* n7 = new TreeNode(7);
	TreeNode* n8 = new TreeNode(8);
	TreeNode* n9 = new TreeNode(9);
	TreeNode* n10 = new TreeNode(10);
	TreeNode* n11 = new TreeNode(11);
	TreeNode* n12 = new TreeNode(12);
	TreeNode* n13 = new TreeNode(13);
	TreeNode* n14 = new TreeNode(14);
	TreeNode* n15 = new TreeNode(15);

	n1->left = n2;
	n1->right = n3;
	n2->left = n4;
	n2->right = n5;
	n4->left = n8;
	n4->right = n9;
	n5->left = n10;
	n5->right = n11;
	n3->left = n6;
	n3->right = n7;
	n6->left = n12;
	n6->right = n13;
	n7->left = n14;
	n7->right = n15;

	Solution236 s;
	TreeNode* n = s.lowestCommonAncestor(n1, n2, n5);
}

void func_test_01()
{
	std::vector<int> nums = { 0,0,1,1,1,2,2,3,3,4 };
	Solution_01 s;
	int k = s.removeDuplicates(nums);
}

void func_test_08()
{
	Solution_8 s;
	int i = s.myAtoi("4193 with words");
}

void func_1208()
{
	std::string s = "abcd", t = "cdef";
	Solution1208 ss;
	ss.equalSubstring(s,t,3);
}

 void func_209()
 {
 	std::vector<int> v = { 2,3,1,2,4,3 };
 	Solution209 s;
 	int r = s.minSubArrayLen(7,v);
 }

 void func_560()
 {
	 std::vector<int> v = {1,1,1};
	 Solution560 s;
	 int r = s.subarraySum(v, 2);
 }

 void func_643()
 {
	 std::vector<int> v = {-1};
	 Solution643 s;
	 double d = s.findMaxAverage(v, 1);
 }

 void func_3_()
 {
	 std::string ss("pwwkew");
	 Solution_3_ s;
	 int r = s.lengthOfLongestSubstring(ss);
 }

 void func_219()
 {
	 std::vector<int> v = { 1,2,3,1,2,3 };
	 int k = 2;
	 Solution219 s;
	 bool b = s.containsNearbyDuplicate(v, k);
 }

 void func_904()
 {
	 std::vector<int> fruits{ 3,3,3,1,2,1,1,2,3,3,4 };
	 Solution904 s;
	 int r = s.totalFruit(fruits);
 }

 void func_76()
 {
	 std::string s = "a", t = "aa";
	 Solution76 slt;
	 std::string rtv = slt.minWindow(s, t);
 }

 void func_1763()
 {
	 std::string s("YazaAay");
	 Solution1763 sln;
	 std::string str = sln.longestNiceSubstring(s);
 }

 void func_1876()
 {
	 std::string s("aababcabc");
	 Solution1876 sln;
	 int cnt = sln.countGoodSubstrings2(s);
 }

 void func_1984()
 {
	 std::vector<int> v = { 90 };
	 Solution1984 sln;
	 int cnt = sln.minimumDifference(v,1);
 }

 void func_2269()
 {
	 Solution2269 sln;
	 int r = sln.divisorSubstrings2(430043,2);
 }

 void func_220()
 {
	 std::vector<int> v = { 1,2,2,3,4,5 };
	 int k = 3, t = 0;
	 Solution220 sln;
	 bool b = sln.containsNearbyAlmostDuplicate(v, k, t);
 }

 void func_copy()
 {
	 std::vector<int> const v = {1,2,3};
	 std::vector<int> v2 = {4,5};
	 size_t pre_size = v2.size();
	 v2.resize(pre_size+v.size());
	 std::copy(v.begin(),v.end(),v2.begin()+pre_size);
 }

 void func_safefunc_test()
 {
	 int* pInt = nullptr;
	 std::shared_ptr<int> p;
	 //std::cout << sizeof(pInt) << " " << sizeof(p) << " " << sizeof(unsigned long) << std::endl;


	 struct TestClass
	 {
		 
		 std::uint32_t m_extValue : 8;//空间闲着浪费，派生类任意使用
		 std::uint32_t m_enabled : 1; //禁止 Component
		 std::uint32_t m_updateCategory : 3;//内部使用，用于 onUpdateTime()
		 std::uint32_t m_serializable : 1;
		 std::uint32_t m_editable : 1;
		 std::uint32_t v;
	 };
	 std::cout << sizeof(TestClass) << std::endl;

	 std::cout << std::numeric_limits<uint16_t>::max() << std::endl;
 }

int main()
{
	thd421::thd421_test();
	return 1;
}